package com.pdsu.graduation_design.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.pdsu.graduation_design.R;
import com.pdsu.graduation_design.component.RoundCornerImageView;
import com.pdsu.graduation_design.domain.Commodity;
import com.squareup.picasso.Picasso;

import java.util.List;

public class PreGoodsGridViewAdapter extends BaseAdapter {

    //数据
    private List<Commodity> commodities;

    public PreGoodsGridViewAdapter(List<Commodity> commodities, Context context) {
        this.commodities = commodities;
        this.context = context;
    }

    private int[] images={R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber,R.drawable.potato,R.drawable.tomtato,R.drawable.cucumber};

    private String[] goodsName={"potato","tomato","cucumber","potato","tomato","cucumber"};

    private Context context;
    private TextView textView,price;
    private RoundCornerImageView roundCornerImageView;

    public PreGoodsGridViewAdapter(Context context) {
        this.context = context;
    }




    @Override
    public int getCount() {
        return commodities.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = View.inflate(context,R.layout.gridview_pregoodsitem_layout,null);

        roundCornerImageView=view.findViewById(R.id.pre_gv_imageview);
        textView=view.findViewById(R.id.pre_gv_title);
        price=view.findViewById(R.id.pre_gv_price);
        Picasso.with(context).load(commodities.get(position).getImage()).into(roundCornerImageView);
        textView.setText(commodities.get(position).getCname());
        price.setText("￥"+commodities.get(position).getPrice()+" 元/斤");


        return view;
    }
}
